package edu.zut.cs.software.propertymanagement.bill.web.spring.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import edu.zut.cs.software.base.web.spring.controller.GenericController;
import edu.zut.cs.software.propertymanagement.bill.domain.PayNotes;
import edu.zut.cs.software.propertymanagement.bill.service.PayNotesManager;

@Controller
//拦截含有favorite的url并处理
@CrossOrigin(origins = "*")
@RequestMapping("/bill1") 
public class PayNotesController extends GenericController<PayNotes, Long,PayNotesManager> {
	PayNotesManager paynotesManager;

	/*
	 * 部署成功后，在浏览器中输入url
	 * http://localhost:8080/universalStore-web/${1.}/${2.value值}
	 * 例子:http://localhost:8080/universalStore-web/commodity/index.html
	*/
	@RequestMapping(value="/index1.html" ,method=RequestMethod.GET)//2.
	public ModelAndView index() {
		ModelAndView mv = new ModelAndView();
		MappingJackson2JsonView jsonView = new MappingJackson2JsonView();
		List<PayNotes> commodityList = paynotesManager.findAll(); 
		//与WEB-INF/pages中视图地址保持一致
		mv.setViewName("commodity/commodity");
		mv.setView(jsonView);
		mv.addObject("commodityList",commodityList);
		return mv;
	}

	@Autowired
	public void setPayNotesManager(PayNotesManager paynotesManager) {
		this.paynotesManager = paynotesManager;
		this.manager = this.paynotesManager;
	}
}
